﻿@*
    Project: Aguafrommars/TheIdServer
    Copyright (c) 2022 @Olivier Lefebvre
*@
@page
@inject IViewLocalizer Localizer
@inject IUrlHelper UrlHelper
@model TwoFactorAuthenticationModel
@{
    ViewData["Title"] = Localizer["Two-factor authentication (2FA)"];
    ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
}

<partial name="_StatusMessage" for="StatusMessage" />
<h4>@ViewData["Title"]</h4>
@if (Model.Is2faEnabled)
{
    if (Model.RecoveryCodesLeft == 0)
    {
        <div class="alert alert-danger">
            <strong>
                @Localizer["You have no recovery codes left."]
            </strong>
            <p>@Localizer["You must <a href=\"{0}\">generate a new set of recovery codes</a> before you can log in with a recovery code.", UrlHelper.Page("./GenerateRecoveryCodes")]</p>
        </div>
    }
    else if (Model.RecoveryCodesLeft == 1)
    {
        <div class="alert alert-danger">
            <strong>
                @Localizer["You have 1 recovery code left."]
            </strong>
            <p>@Localizer["You can <a href=\"{0}\">generate a new set of recovery codes</a>.", UrlHelper.Page("./ GenerateRecoveryCodes")]</p>
        </div>
    }
    else if (Model.RecoveryCodesLeft <= 3)
    {
        <div class="alert alert-warning">
            <strong>You have @Model.RecoveryCodesLeft recovery codes left.</strong>
            <p>@Localizer["You should <a href=\"{0}\">generate a new set of recovery codes</a>.", UrlHelper.Page("./ GenerateRecoveryCodes")]</p>
        </div>
    }

    if (Model.IsMachineRemembered)
    {
        <form method="post" style="display: inline-block">
            <button type="submit" class="w-100 btn btn-lg btn-primary">@Localizer["Forget this browser"]</button>
        </form>
    }
    <a asp-page="./Disable2fa" class="btn btn-secondary">Disable 2FA</a>
    <a asp-page="./GenerateRecoveryCodes" class="btn btn-secondary">
        @Localizer["Reset recovery codes"]
    </a>
}

<h5>@Localizer["Authenticator app"]</h5>
<div class="row">
    <div class="col-md-6">
        @if (!Model.HasAuthenticator)
        {
            <a id="enable-authenticator" asp-page="./EnableAuthenticator" class="w-100 btn btn-lg btn-primary">@Localizer["Add authenticator app"]</a>
        }
        else
        {
            <a id="enable-authenticator" asp-page="./EnableAuthenticator" class="w-100 btn btn-lg btn-primary mb-2">@Localizer["Setup authenticator app"]</a>
            <a id="reset-authenticator" asp-page="./ResetAuthenticator" class="w-100 btn btn-lg btn-secondary">@Localizer["Reset authenticator app"]</a>
        }

    </div>
</div>

@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
